class ReadersController < ApplicationController
  before_action :set_reader, only: [:show, :edit, :update]

  def index
    @readers = Reader.all
  end

  def show
  end

  def new
    @reader = Reader.new
  end

  def edit
  end

  def create
    @reader = Reader.new(reader_params)
    respond_to do |format|
      if @reader.save
        format.html { redirect_to readers_path, notice: 'Reader was successfully created.' }
        format.json { render action: 'show', status: :created, location: @reader }
      else
        format.html { render action: 'new' }
        format.json { render json: @reader.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @reader.update(reader_params)
        format.html { redirect_to readers_path, notice: 'Reader was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @reader.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @reader = Reader.find(params[:reader_id])
    @reader.destroy
    respond_to do |format|
      format.html { redirect_to readers_path }
      format.json { head :no_content }
    end
  end

  private
    def set_reader
      @reader = Reader.find(params[:id])
    end

    def reader_params
      params.fetch(:reader, {}).permit(:description, :ip_address)
    end
end
